//////////////////////////////////////
// Fast Container Library           //
// MIT License - Copyright (c) 2012 //
//////////////////////////////////////

#pragma once

#include "vector_map.h"


FC_NAMESPACE_BEGIN


template <class Key, class Value, size_t N, class Compare, class Allocator>
class fixed_vector_map : public vector_map<Key, Value, Compare, Allocator>
{
public:
	typedef fixed_vector_map<Key, Value, N, Compare, Allocator>		this_type;
	typedef vector_map<Key, Value, Compare, Allocator>				base_type;
	typedef typename base_type::pair_type							pair_type;
	typedef typename base_type::pointer								pointer;

	using base_type::m_allocator;
	using base_type::m_begin;
	using base_type::m_end;
	using base_type::m_capacity;

	typedef aligned_buffer<N * sizeof(pair_type), FC_ALIGNOF(pair_type)> buffer_type;

	explicit fixed_vector_map( const Compare& comp = Compare() )
		: base_type(comp)
		{
			init();
		}

	template<class Iter>
		fixed_vector_map( Iter first, Iter last, const Compare& comp = Compare() )
		: base_type(comp)
		{
			init();
			base_type::insert(first, last);
		}

	fixed_vector_map( const this_type& x )
		: base_type()
		{
			init();
			*this = x;
		}

	this_type& operator =( const this_type& x )
	{
		base_type::operator =(x);
		return *this;
	}

	bool has_overflowed() const
	{
		return m_begin != get_buffer();
	}

	void reset()
	{
		if( m_capacity )
		{
			base_type::clear();
			base_type::deallocate();
		}

		init();
	}

	void init()
	{
		m_begin = m_end = (pointer)m_buffer.data;
		m_capacity = m_begin + N;
		m_allocator.set_buffer(m_begin);
	}

	pointer get_buffer() const
	{
		return (pointer)m_buffer.data;
	}

protected:
	buffer_type m_buffer;

};



FC_NAMESPACE_END
